<template>
  <div>
    home
    <div v-for="item in posts" :key="item.id">{{ item.title }}</div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import axios from 'axios'
export default {
  metaInfo: {
    title: "首页",
  },
  computed: {
    ...mapState(["posts"])
  },
  //Vue Ssr 为服务端渲染提供的一个生命周期函数
  serverPrefetch() {
    //调用action
    return this.getPosts()
  },
  methods: {
    ...mapActions(['getPosts'])
  },
  async created() {
    const data = await axios.get('index.json')
    console.log(data,'data');
  }
}
</script>

<style>
</style>